﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using RED_NET_Core.Helper;

namespace RED_NET_Core.DAL
{
    public class NewsFeed_DAL
    {
        //构造函数
        public NewsFeed_DAL()
        { }

        #region[返回好友相片最新动态的datatable]

        /// <summary>
        /// 好友最新动态
        /// </summary>
        /// <param name="UId"></param> 登录者的ID
        /// <returns></returns>
        public DataTable GetNewsFeedOfPhotoOfUser(int UId)
        {

            //获取最新照片的列表
            SqlHelper helper = new SqlHelper();
            String sqlstr = "SELECT top 20 _PhotoOfUId,_PhotoId,_PhotoName,_PhotoOfAlbumId,_PhotoContent,_PhotoUrl,"
               + "_PhotoUpdateTime FROM _Photo Where _PhotoOfUId in (SELECT _AttentionId FROM _UserRel WHERE _UId = @UId)"
               + "order by _PhotoUpdateTime desc";
            //String sqlstr = "SELECT _AttentionId FROM _UserRel WHERE _UId = @UId";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@UId",UId)
            };
            SqlCommand sqlcmd = helper.GetCommand(sqlstr, param);
            DataTable dt = new DataTable();
            try
            {
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                dt.Load(sdr);
                sdr.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //获取最新照片对应用户的头像URL
            String sqlstr2 = "SELECT _AvatarUrl,_UId,_NickName FROM _Users WHERE _UId in" +
                "(SELECT top 20 _PhotoOfUId FROM _Photo Where _PhotoOfUId in" +
                "(SELECT _AttentionId FROM _UserRel WHERE _UId = @UId) order by _PhotoUpdateTime desc)";
            SqlParameter[] param2 = new SqlParameter[]
            {
                new SqlParameter("@UId",UId)
            };
            sqlcmd = helper.GetCommand(sqlstr2, param2);
            DataTable dt2 = new DataTable();
            try
            {
                SqlDataReader sdr2 = sqlcmd.ExecuteReader();
                dt2.Load(sdr2);
                sdr2.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //给dt增加一列并循环把dt2中的_AvatarUrl克隆到dt的末尾列上
            DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn("_NickName", typeof(string));
            dt.Columns.Add(dc2);
            DataRow[] dr = dt.Select();
            DataRow[] dr2 = dt2.Select();
            int nowUId, nowUId2;
            for (int i = 0; i < dr.Length; i++)
            {
                nowUId = Int32.Parse(dt.Rows[i]["_PhotoOfUId"].ToString());
                for (int j = 0; j < dr2.Length; j++)
                {
                    nowUId2 = Int32.Parse(dt2.Rows[j]["_UId"].ToString());
                    if (nowUId == nowUId2)//如果用户ID对应
                    {
                        dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvaTarUrl"];
                        dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        break;
                    }
                }
            }
            return dt;
        }

        #endregion

        #region[返回好友日志最新动态的datatable]

        /// <summary>
        /// 返回好友日志最新动态
        /// </summary>
        /// <param name="UId"></param>当前登录的用户ID
        /// <returns></returns>
        public DataTable GetNewsFeedOfNewsOfUser(int UId)
        {

            //获取最新日志的列表
            SqlHelper helper = new SqlHelper();
            String sqlstr = "SELECT top 20 _UId,_Id,_ReplyNum,_Title,_Content,_UpdateTime FROM _News "
               + "Where _UId in (SELECT _AttentionId FROM _UserRel WHERE _UId = @UId) "
               + "AND _Level=@Two AND _IsDeleted = @False order by _UpdateTime desc";
            //String sqlstr = "SELECT _AttentionId FROM _UserRel WHERE _UId = @UId";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@UId",UId),
                new SqlParameter("@Three",3),
                new SqlParameter("@Two",2),
                new SqlParameter("@False",false)
            };
            SqlCommand sqlcmd = helper.GetCommand(sqlstr, param);
            DataTable dt = new DataTable();
            try
            {
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                dt.Load(sdr);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //获取最新照片对应用户的头像URL
            String sqlstr2 = "SELECT _AvatarUrl,_UId,_NickName FROM _Users WHERE _UId in "
               + "(SELECT top 20 _UId FROM _News Where _UId in "
               + "(SELECT _AttentionId FROM _UserRel WHERE _UId = @UId) "
               + "AND _Level=@Two AND _IsDeleted = @False order by _UpdateTime desc)";
            SqlParameter[] param2 = new SqlParameter[]
            {
                new SqlParameter("@UId",UId),
                new SqlParameter("@Three",3),
                new SqlParameter("@Two",2),
                new SqlParameter("@False",false)
            };
            sqlcmd = helper.GetCommand(sqlstr2, param2);
            DataTable dt2 = new DataTable();
            try
            {
                SqlDataReader sdr2 = sqlcmd.ExecuteReader();
                dt2.Load(sdr2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //给dt增加一列并循环把dt2中的_AvatarUrl克隆到dt的末尾列上
            DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn("_NickName", typeof(string));
            dt.Columns.Add(dc2);
            DataRow[] dr = dt.Select();
            DataRow[] dr2 = dt2.Select();
            int nowUId, nowUId2;
            for (int i = 0; i < dr.Length; i++)
            {
                nowUId = Int32.Parse(dt.Rows[i]["_UId"].ToString());
                for (int j = 0; j < dr2.Length; j++)
                {
                    nowUId2 = Int32.Parse(dt2.Rows[j]["_UId"].ToString());
                    if (nowUId == nowUId2)//如果用户ID对应
                    {
                        dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvaTarUrl"];
                        dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        break;
                    }
                }
            }
            return dt;
        }

        #endregion

        #region[返回学院内各班相片最新动态的datatable]

        /// <summary>
        /// 学院各班最新动态
        /// </summary>
        /// <param name="tCollegeId"></param>学院ID
        /// <returns></returns>
        public DataTable GetNewsFeedOfPhotoOfUsersByCollege(int tCollegeId)
        {

            //获取最新照片的列表
            SqlHelper helper = new SqlHelper();
            String sqlstr = "SELECT top 20 _PhotoOfUId,_PhotoId,_PhotoOfAlbumId,_PhotoName,_PhotoContent,_PhotoUrl,"
               + "_PhotoUpdateTime FROM _Photo Where _PhotoOfUId in (SELECT _UId FROM _Users WHERE _College = @CollegeId)"
               + "order by _PhotoUpdateTime desc";
            //String sqlstr = "SELECT _AttentionId FROM _UserRel WHERE _UId = @UId";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@CollegeId",tCollegeId)
            };
            SqlCommand sqlcmd = helper.GetCommand(sqlstr, param);
            DataTable dt = new DataTable();
            try
            {
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                dt.Load(sdr);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //获取最新照片对应用户的头像URL
            String sqlstr2 = "SELECT _UId,_NickName,_AvatarUrl FROM _Users WHERE _College = @CollegeId";
            SqlParameter[] param2 = new SqlParameter[]
            {
                new SqlParameter("@CollegeId",tCollegeId)
            };
            sqlcmd = helper.GetCommand(sqlstr2, param2);
            DataTable dt2 = new DataTable();
            try
            {
                SqlDataReader sdr2 = sqlcmd.ExecuteReader();
                dt2.Load(sdr2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //给dt增加一列并循环把dt2中的_AvatarUrl克隆到dt的末尾列上
            DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn("_NickName", typeof(string));
            dt.Columns.Add(dc2);
            DataRow[] dr = dt.Select();
            DataRow[] dr2 = dt2.Select();
            int nowUId, nowUId2;
            for (int i = 0; i < dr.Length; i++)
            {
                nowUId = Int32.Parse(dt.Rows[i]["_PhotoOfUId"].ToString());
                for (int j = 0; j < dr2.Length; j++)
                {
                    nowUId2 = Int32.Parse(dt2.Rows[j]["_UId"].ToString());
                    if (nowUId == nowUId2)//如果用户ID对应
                    {
                        dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvaTarUrl"];
                        dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        break;
                    }
                }
            }
            return dt;
        }

        #endregion

        #region[返回学院内各班日志最新动态的datatable]


        public DataTable GetNewsFeedOfNewsOfUserByCollege(int tCollegeId)
        {

            //获取最新照片的列表
            SqlHelper helper = new SqlHelper();
            String sqlstr = "SELECT top 20 _UId,_ReplyNum,_Title,_Id,_Content,_UpdateTime FROM _News "
               + "Where  _Level = @Two AND _UId in (SELECT _UId FROM _Users WHERE _College = @CollegeId) "
               + "AND _IsDeleted = @False order by _UpdateTime desc";
            //String sqlstr = "SELECT _AttentionId FROM _UserRel WHERE _UId = @UId";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@CollegeId",tCollegeId),
                new SqlParameter("@Three",3),
                new SqlParameter("@Two",2),
                new SqlParameter("@False",false)
            };
            SqlCommand sqlcmd = helper.GetCommand(sqlstr, param);
            DataTable dt = new DataTable();
            try
            {
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                dt.Load(sdr);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //获取最新日志对应用户的头像URL
            String sqlstr2 = "SELECT _AvatarUrl,_UId,_NickName FROM _Users WHERE _UId in "
               + "(SELECT _UId FROM _Users WHERE _College = @CollegeId)";
            SqlParameter[] param2 = new SqlParameter[]
            {
                new SqlParameter("@CollegeId",tCollegeId),
            };
            sqlcmd = helper.GetCommand(sqlstr2, param2);
            DataTable dt2 = new DataTable();
            try
            {
                SqlDataReader sdr2 = sqlcmd.ExecuteReader();
                dt2.Load(sdr2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //给dt增加一列并循环把dt2中的_AvatarUrl克隆到dt的末尾列上
            DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn("_NickName", typeof(string));
            dt.Columns.Add(dc2);
            DataRow[] dr = dt.Select();
            DataRow[] dr2 = dt2.Select();
            int nowUId, nowUId2;
            for (int i = 0; i < dr.Length; i++)
            {
                nowUId = Int32.Parse(dt.Rows[i]["_UId"].ToString());
                for (int j = 0; j < dr2.Length; j++)
                {
                    nowUId2 = Int32.Parse(dt2.Rows[j]["_UId"].ToString());
                    if (nowUId == nowUId2)//如果用户ID对应
                    {
                        dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvaTarUrl"];
                        dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        break;
                    }
                }
            }
            return dt;
        }

        #endregion

        #region[返回学院各学院相片最新动态的datatable]

        /// <summary>
        /// 学院各班最新动态
        /// </summary>
        /// <param name="tCollegeId"></param>学院ID
        /// <returns></returns>
        public DataTable GetNewsFeedOfPhotoOfColleges()
        {

            //获取最新照片的列表
            SqlHelper helper = new SqlHelper();
            String sqlstr = "SELECT top 20 _PhotoOfUId,_PhotoId,_PhotoName,_PhotoOfAlbumId,_PhotoContent,_PhotoUrl,"
               + "_PhotoUpdateTime FROM _Photo Where _PhotoOfUId in (SELECT _UId FROM _Users WHERE _Right = @Right)"
               + "order by _PhotoUpdateTime desc";
            //String sqlstr = "SELECT _AttentionId FROM _UserRel WHERE _UId = @UId";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@Right",1)//确定学院管理员的权限，修改下即可
            };
            SqlCommand sqlcmd = helper.GetCommand(sqlstr, param);
            DataTable dt = new DataTable();
            try
            {
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                dt.Load(sdr);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //获取最新照片对应用户的头像URL
            String sqlstr2 = "SELECT _AvatarUrl,_UId,_NickName FROM _Users WHERE _UId in "
               + "(SELECT _UId FROM _Users WHERE _Right = @Right)";
            SqlParameter[] param2 = new SqlParameter[]
            {
                new SqlParameter("@Right",1)//确定学院管理员的权限，修改下即可
            };
            sqlcmd = helper.GetCommand(sqlstr2, param2);
            DataTable dt2 = new DataTable();
            try
            {
                SqlDataReader sdr2 = sqlcmd.ExecuteReader();
                dt2.Load(sdr2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //给dt增加一列并循环把dt2中的_AvatarUrl克隆到dt的末尾列上
            DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn("_NickName", typeof(string));
            dt.Columns.Add(dc2);
            DataRow[] dr = dt.Select();
            DataRow[] dr2 = dt2.Select();
            int nowUId, nowUId2;
            for (int i = 0; i < dr.Length; i++)
            {
                nowUId = Int32.Parse(dt.Rows[i]["_PhotoOfUId"].ToString());
                for (int j = 0; j < dr2.Length; j++)
                {
                    nowUId2 = Int32.Parse(dt2.Rows[j]["_UId"].ToString());
                    if (nowUId == nowUId2)//如果用户ID对应
                    {
                        dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvaTarUrl"];
                        dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        break;
                    }
                }
            }
            return dt;
        }

        #endregion

        #region[返回各学院日志最新动态的datatable]


        public DataTable GetNewsFeedOfNewsOfColleges()
        {

            //获取最新日志的列表
            SqlHelper helper = new SqlHelper();
            String sqlstr = "SELECT top 20 _UId,_ReplyNum,_Title,_Id,_Content,_UpdateTime FROM _News "
               + "Where _UId in (SELECT _UId FROM _Users WHERE _Right = @Right) "
               + "AND _Level=@Two AND _IsDeleted = @False order by _UpdateTime desc";
            //String sqlstr = "SELECT _AttentionId FROM _UserRel WHERE _UId = @UId";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@Right",1),//院管理员的权限
                new SqlParameter("@Three",3),
                new SqlParameter("@Two",2),
                new SqlParameter("@False",false)
            };
            SqlCommand sqlcmd = helper.GetCommand(sqlstr, param);
            DataTable dt = new DataTable();
            try
            {
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                dt.Load(sdr);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //获取最新日志对应用户的头像URL
            String sqlstr2 = "SELECT _AvatarUrl,_UId,_NickName FROM _Users WHERE _UId in "
               + "(SELECT _UId FROM _Users WHERE _Right = @Right)";
            SqlParameter[] param2 = new SqlParameter[]
            {
                new SqlParameter("@Right",1)//院管理员的权限
            };
            sqlcmd = helper.GetCommand(sqlstr2, param2);
            DataTable dt2 = new DataTable();
            try
            {
                SqlDataReader sdr2 = sqlcmd.ExecuteReader();
                dt2.Load(sdr2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //给dt增加一列并循环把dt2中的_AvatarUrl克隆到dt的末尾列上
            DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
            dt.Columns.Add(dc);
            DataColumn dc2 = new DataColumn("_NickName", typeof(string));
            dt.Columns.Add(dc2);
            DataRow[] dr = dt.Select();
            DataRow[] dr2 = dt2.Select();
            int nowUId, nowUId2;
            for (int i = 0; i < dr.Length; i++)
            {
                nowUId = Int32.Parse(dt.Rows[i]["_UId"].ToString());
                for (int j = 0; j < dr2.Length; j++)
                {
                    nowUId2 = Int32.Parse(dt2.Rows[j]["_UId"].ToString());
                    if (nowUId == nowUId2)//如果用户ID对应
                    {
                        dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvaTarUrl"];
                        dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        break;
                    }
                }
            }
            return dt;
        }

        #endregion



        //新版最新动态_增删改查

        #region[返回最新动态(兼容全部要求)]

        /// <summary>
        ///  返回最新动态的信息
        /// </summary>
        /// <param name="iUId">调用该函数的UId</param>
        /// <param name="iCollegeId">调用该函数的iCollege（在搜索学院下班级信息时用到，不是用此功能则设置任何数都可）</param>
        /// <param name="iNumber">第n批的15个最新动态（页面下拉时增加信息用）</param>
        /// <param name="iGetWhatNewsFeed">取最新动态信息的种类，0为好友动态，1为学院下班级动态，2为学院动态</param>
        /// <returns></returns>
        public DataTable GetNewsFeed(int iUId, int iCollegeId, int iNumber, int iGetWhatNewsFeed)
        {

            


            DataTable dt, dt2;
            SqlHelper helper = new SqlHelper();

            /*huzohe   fuhe tiaojian zilushu*/
            string sql = "Select count([_NewsFeedId]) From _NewsFeed where _BeOfUserId in (Select _AttentionId FROM _UserRel WHERE _UId = @UId)";
            SqlParameter[] param1 = new SqlParameter[]
                {
                    new SqlParameter("@UId",iUId)
                };
            
            SqlCommand cmd0 = helper.GetCommand(sql, param1);
            cmd0.Dispose();
            int count = Convert.ToInt32(cmd0.ExecuteScalar());
            int number = count - 10 * (iNumber - 1);
            if (number > 0)
            {
                /*------好友最新动态-----*/
                if (iGetWhatNewsFeed == 0)
                {
                    //搜索出当前最新的15条（可能是15-30条）



                    string cmdText = "Select top 10 * From  " +
                        "(Select top " + number + " * From _NewsFeed where _BeOfUserId in" +
                        "(Select _AttentionId FROM _UserRel WHERE _UId = @UId)" +
                        " order by _UpdateTime asc) As A order by _UpdateTime desc";

                    SqlParameter[] param2 = new SqlParameter[]
                {
                    new SqlParameter("@UId",iUId)
                };
                    //SqlParameter[] paras = new SqlParameter[]{new SqlParameter("@tblName",SqlDbType.VarChar),
                    //new SqlParameter("@strFields",SqlDbType.VarChar),
                    //new SqlParameter("@strOrder",SqlDbType.VarChar),
                    //new SqlParameter("@strOrderType",SqlDbType.VarChar),
                    //new SqlParameter("@PageSize",SqlDbType.Int),
                    //new SqlParameter("@PageIndex",SqlDbType.Int),
                    //new SqlParameter("@strWhere",SqlDbType.Int)};


                    SqlCommand cmd = helper.GetCommand(cmdText, param2);
                    dt = new DataTable();
                    try
                    {
                        SqlDataReader dr = cmd.ExecuteReader();
                        dt.Load(dr);
                        dr.Dispose();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                /*-----学院各班最新动态------*/
                else if (iGetWhatNewsFeed == 1)
                {
                    string cmdText = "Select top 15 * From" +
                        "(Select top " + 15 * iNumber + " * From _NewsFeed Where _BeOfUserId in" +
                        "(Select _UId From _Users Where _College = @College And _Right = @Right)" +
                        "order by _UpdateTime desc) As A order by _UpdateTime asc";
                    SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@College",iCollegeId),
                    new SqlParameter("@Right","0")//团支书的Right值
                };
                    SqlCommand cmd = helper.GetCommand(cmdText, param);
                    dt = new DataTable();
                    try
                    {
                        SqlDataReader dr = cmd.ExecuteReader();
                        dt.Load(dr);
                        dr.Dispose();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                /*-------学院用户的最新动态-------*/
                else if (iGetWhatNewsFeed == 2)
                {
                    string cmdText = "Select top 15 * From" +
                        "(Select top " + 15 * iNumber + " * From _NewsFeed Where _BeOfUserId in" +
                        "(Select _UId From _Users Where _Right = @Right)" +
                        "order by _UpdateTime desc)  As A order by _UpdateTime asc";
                    SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@Right",1)//学院的Right值
                };
                    SqlCommand cmd = helper.GetCommand(cmdText, param);
                    dt = new DataTable();
                    try
                    {
                        SqlDataReader dr = cmd.ExecuteReader();
                        dt.Load(dr);
                        dr.Dispose();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    return null;
                }
                //搜索出对应信息的用户的头像、昵称
                string cmdText2 = "Select _AvatarUrl,_UId,_NickName FROM _Users WHERE _UId in(0";//加个0是为了防止无数据时的错误
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dataRow = dt.Rows[i];
                    cmdText2 += ",";
                    cmdText2 += dataRow["_BeOfUserId"].ToString();
                }
                cmdText2 += ")";
                SqlCommand cmd2 = helper.GetCommand(cmdText2, null);
                dt2 = new DataTable();
                try
                {
                    SqlDataReader dr = cmd2.ExecuteReader();
                    dt2.Load(dr);
                    dr.Dispose();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                DataColumn dc = new DataColumn("_AvatarUrl", typeof(string));
                dt.Columns.Add(dc);
                DataColumn dc2 = new DataColumn("_NickName", typeof(string));
                dt.Columns.Add(dc2);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    for (int j = 0; j < dt2.Rows.Count; j++)
                    {
                        if (dt.Rows[i]["_BeOfUserId"].ToString() == dt2.Rows[j]["_UId"].ToString())
                        {
                            dt.Rows[i]["_AvatarUrl"] = dt2.Rows[j]["_AvatarUrl"];
                            dt.Rows[i]["_NickName"] = dt2.Rows[j]["_NickName"];
                        }
                    }
                }
                return dt;
            }
            else return null;
        }

        #endregion

        #region[增加动态]

        public bool InsertNewsFeed(int iBeOfUserId, int iType, string sName, string sContent, DateTime tUpdateTime,
            int iContentId, int iFatherId)
        {
            SqlHelper helper = new SqlHelper();
            string cmdText = "Insert Into _NewsFeed(_BeOfUserId,_Type,_Name,_Content,_UpdateTime,_ContentId,_FatherId)" +
                "Values(@BeOfUserId,@Type,@Name,@Content,@UpdateTime,@ContentId,@FatherId)";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@BeOfUserId",iBeOfUserId),
                new SqlParameter("@Type",iType),
                new SqlParameter("@Name",sName),
                new SqlParameter("@Content",sContent),
                new SqlParameter("@UpdateTime",tUpdateTime),
                new SqlParameter("@ContentId",iContentId),
                new SqlParameter("@FatherId",iFatherId)
            };
            SqlCommand cmd = helper.GetCommand(cmdText, param);
            try
            {
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region[删除动态]

        public bool DeleteNewsFeed(int iType, int iContentId)
        {
            SqlHelper helper = new SqlHelper();
            string cmdText = "Delete _NewsFeed Where _ContentId = @ContentId And _Type= @Type";
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@ContentId",iContentId),
                new SqlParameter("@Type",iType)
            };
            SqlCommand cmd = helper.GetCommand(cmdText, param);
            try
            {
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

    }
}
